﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace SSP
{
    class SSPMovie : SSPNode
    {
        Video video;
        VideoPlayer player;
        Texture2D videoTexture;
        
        public SSPMovie()
        {

        }

        public SSPMovie(string fileName)
        {
            video = SSPDirector.Instance.gameInstance.Content.Load<Video>(fileName);
            player = new VideoPlayer();
        }

        public override void draw()
        {
            // Only call GetTexture if a video is playing or paused
            if (player.State != MediaState.Stopped)
                videoTexture = player.GetTexture();

            // Drawing to the rectangle will stretch the 
            // video to fill the screen
            Rectangle screen = new Rectangle(SSPDirector.Instance.graphicsInstance.GraphicsDevice.Viewport.X,
                SSPDirector.Instance.graphicsInstance.GraphicsDevice.Viewport.Y,
                SSPDirector.Instance.graphicsInstance.GraphicsDevice.Viewport.Width,
                SSPDirector.Instance.graphicsInstance.GraphicsDevice.Viewport.Height);
            
            // Draw the video, if we have a texture to draw.
            if (videoTexture != null)
            {
                SSPDirector.Instance.spriteBatchInstance.Draw(videoTexture, screen, Color.White);
            }

        }

        public override void update()
        {
            /*
            if (player.State == MediaState.Stopped)
            {
                player.IsLooped = false;
                player.Play(video);
            }
            */
        }

        public bool isDone()
        {
            if (player.State == MediaState.Playing)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        public void Stop()
        {
            player.Stop();
        }

        public void Play()
        {
            player.Play(video);
        }

        public void Pause()
        {
            player.Pause();
        }
       
    }
}
